import config from '../../config/config'
import Crypt from "../../utils/Crypt";
import PageModel from "../../models/Page";
const pageModel = new PageModel()

Page({
  data: {

    baseUrl: config.app_base_url,
    size: 'small',
    style: {},
    id: 0

  },
  onLoad: function (options) {
    console.log(options)
    this.setData({ id: options.id })
  },
  onShow() {
    const _change = () => {
      setTimeout(() => {
        if (this.data.size === 'small') {
          this.setData({
            size: 'big'
          })
        }
        else if (this.data.size === 'default') {
          this.setData({
            size: 'big'
          })
        }
        else if (this.data.size === 'big') {
          this.setData({
            size: 'small'
          })
        }
        // console.log(this.data.size)
        _change()
      }, 500)
    }
    _change()
  },

  get() {
    pageModel.red({ id: this.data.id }).then(response => {
      let { data } = response
      data = Crypt.parse(data)
      console.log(data)
      wx.showToast({
        icon: 'none',
        title: `恭喜: ￥${data.red.amount}已存入您的余额`,
        duration: 1500
      })
      setTimeout(() => {
        wx.switchTab({
          url: '/pages/center/index'
        })
      }, 1500)
    })
  }
});
